package com.zhiyou.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhiyou.mapper.CourseMapper;
import com.zhiyou.mapper.SpeakerMapper;
import com.zhiyou.pojo.Course;
import com.zhiyou.pojo.CourseExample;
import com.zhiyou.pojo.CourseExample.Criteria;
import com.zhiyou.pojo.Speaker;
import com.zhiyou.pojo.SpeakerExample;

@Service
public class CourseService {

	
	@Autowired
	private CourseMapper courseMapper;
	
	public List<Course> selectAll(){
		
		return courseMapper.selectByExampleWithBLOBs(new CourseExample());
	}
    public void saveOrUpdate(Course course){
		
		if(null!=course.getId() && course.getId()!=0){
			courseMapper.updateByPrimaryKeyWithBLOBs(course);
		}else{
			
			courseMapper.insert(course);
		}
	}
    public int delById(int id){
		return courseMapper.deleteByPrimaryKey(id);
	}
   public int delBatchByIds(Integer[] ids){
		
		CourseExample example = new CourseExample();
		
		 Criteria createCriteria = example.createCriteria();
		
		 List<Integer> list = new ArrayList<Integer>();
		 Collections.addAll(list, ids);
		 createCriteria.andIdIn(list);
		return courseMapper.deleteByExample(example);
	}
	
	public Course selectById(int id){
		
		return courseMapper.selectByPrimaryKey(id);
	}
	public List<Course> selectBySubjectId(Integer subjectId){
		CourseExample example = new CourseExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andSubjectIdEqualTo(subjectId);
		List<Course> courseList = courseMapper.selectByExampleWithBLOBs(example);
		return courseList;
	}
}
